function Trim(strSource){return strSource.replace(/^\s*/,'').replace(/\s*$/,'');}

//xmlHttp
var xmlHttp = false;
try{xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e){
	try{xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
	catch(e2){xmlHttp=false;}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined'){xmlHttp = new XMLHttpRequest();}


function doSearch() {
 var obj=document.getElementById("wd").value;
 if (obj=="") {
    alert('请输入搜索内容!');
    document.getElementById("wd").focus();
    return false;
 }
 return true;
}
function show(o){
	for(var i=1; i<3;i++)
	{
		document.getElementById('a_'+i).className='';
		document.getElementById('u_'+i).style.display='none';
	}
	document.getElementById('a_'+o).className='on';
	document.getElementById('u_'+o).style.display='block';
}
var usercount=12;//特约模板设计师的个数
function iscroll(l)
{
	var o1='u_1';
	var o2='u_2';
	if(l=='l')
	{
		if(document.getElementById('user_u').scrollLeft>=document.getElementById(o1).offsetWidth)
			Scroll('l',0,0)//document.getElementById('user_u').scrollLeft=0;
		else
			Scroll('l',97,0)//document.getElementById('user_u').scrollLeft+=97;
	}
	else if(l=='r')
	{
		if(document.getElementById('user_u').scrollLeft>0)
			Scroll('r',97,0)//document.getElementById('user_u').scrollLeft-=97;
		else
			Scroll('l',97*(usercount-3),0)//document.getElementById('user_u').scrollLeft=97*(usercount-3);
	}
}
function Scroll(t,s,n)
{
	n=parseInt(n);
	s=parseInt(s);
	if(t=='l')
	{
		if(s==0)
		{
			if(document.getElementById('user_u').scrollLeft>0)
			{
				document.getElementById('user_u').scrollLeft-=10;
				setTimeout("Scroll('"+t+"','"+s+"','"+n+"')",10);
			}
		}
		else
		{
			if(n<s)
			{
				n=n+10;
				if(n<s)
				{
					document.getElementById('user_u').scrollLeft+=10;
					setTimeout("Scroll('"+t+"','"+s+"','"+n+"')",10);
				}
				else
				{document.getElementById('user_u').scrollLeft+=7;}
			}
		}
	}
	else
	{
			if(n<s)
			{
				n=n+10;
				if(n<s)
				{
					document.getElementById('user_u').scrollLeft-=10;
					setTimeout("Scroll('"+t+"','"+s+"','"+n+"')",10);
				}
				else
				{document.getElementById('user_u').scrollLeft-=7;}
			}

	}
}

function CheckRegName() {
    var obj=Trim(document.getElementById("username").value);
    var txt=document.getElementById("regname");
    if (obj=='') {
        txt.innerHTML="<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;用户名不能为空</div>";
      }else if(obj.length<6){
        txt.innerHTML="<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;长度必须大于5位</div>";
      }else {
        RegNameCheck();
      }
}
function RegNameCheck() {
    var UserName=document.getElementById("username").value;
    var UserNameUrl="ajax/check_name.php?username="+escape(UserName);
    xmlHttp.open('GET',UserNameUrl,true);
    xmlHttp.onreadystatechange=UpdateRegName;
    xmlHttp.send(null);
}
function UpdateRegName() {
    if (xmlHttp.readyState==3) {
        document.getElementById("regname").innerHTML="<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;连接中</div>";
    }
    if (xmlHttp.readyState==4) {
        var uback=xmlHttp.responseText;
        if (uback=='1') {
            document.getElementById("regname").innerHTML="<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;用户名已存在</div>";

        }else if(uback=='0'){
            document.getElementById("regname").innerHTML="<div class='Box_green'>&nbsp;&nbsp;&nbsp;&nbsp;</div>";

        }else {
            document.getElementById("regname").innerHTML="<div class='Box_yellow'>&nbsp;&nbsp;&nbsp;&nbsp;服务器故障</div>";
        }
    }
}
function CheckPwd() {
    var obj=Trim(document.getElementById("pwd").value);
    var txt=document.getElementById("regpwd");
    if (obj=='') {
        txt.innerHTML="<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;密码不能为空</div>";
    }else if (obj.length<6) {
        txt.innerHTML="<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;密码必须大于5位</div>";
    }else {
        txt.innerHTML="<div class='Box_green'>&nbsp;&nbsp;&nbsp;&nbsp;</div>";
    }
}
function CheckRePwd(){
    var obj=Trim(document.getElementById("pwd1").value);
    var obj2=Trim(document.getElementById("pwd").value);
    var txt=document.getElementById("regpwd1");
    if (obj=='') {
		txt.innerHTML = "<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;请再次输入密码</div>";
    }else if (obj!=obj2) {
        txt.innerHTML="<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;两次输入密码不一致</div>";
    }else {
        txt.innerHTML="<div class='Box_green'>&nbsp;&nbsp;&nbsp;&nbsp;</div>";
    }
}
function CheckEmail() {
    var obj=Trim(document.getElementById("Email").value);
    var txt=document.getElementById("regmail");
    if (obj=='') {
        txt.innerHTML="<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;请输入邮箱</div>";
    }else if(!CheckEmailAddress(obj)){
        txt.innerHTML="<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;邮箱格式不正确</div>";
    }else {
        EmailCheck();
        }
}
function CheckEmailAddress(e) {
     var ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.+@-_QWERTYUIOPASDFGHJKLZXCVBNM";
     for (var i=0; i<e; i++) {
         if (ok.indexOf(e.charAt(i))<0) {
             return false;
         }
     }
     if (e.indexOf("@")<=0) {
        return false;
     }
     if (e.indexOf(".")<0) {
        return false;
     }
     return true;
}

function EmailCheck() {
    var Email=Trim(document.getElementById("Email").value);
    var url="ajax/check_email.php?email="+escape(Email);
    xmlHttp.open('GET',url,true);
    xmlHttp.onreadystatechange=UpdateEmail;
    xmlHttp.send(null);

}
function UpdateEmail() {
   if(xmlHttp.readyState==3){
       document.getElementById("regmail").innerHTML="<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;连接中</div>";
   }
   if (xmlHttp.readyState==4) {
       var eback=xmlHttp.responseText;
       if (eback=='1') {
            document.getElementById("regmail").innerHTML="<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;邮箱已存在</div>";
       }else if(eback=='0'){
            document.getElementById("regmail").innerHTML="<div class='Box_green'>&nbsp;&nbsp;&nbsp;&nbsp;</div>";
       }else {
            document.getElementById("regmail").innerHTML="<div class='Box_yellow'>&nbsp;&nbsp;&nbsp;&nbsp;服务器故障</div>";
       }
   }
}

function CheckYzm() {
    var obj=Trim(document.getElementById("Yzm").value);
    var txt=document.getElementById("regcode");
    var reyzm=/^[0-9]+$/;
    if (obj=='') {
        txt.innerHTML="<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;验证码不能为空</div>";
         result=false;
    }else if(obj.length!=4){
        txt.innerHTML= "<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;验证码错误</div>";
         result=false;
    }else if(!reyzm.test(obj)){
        txt.innerHTML= "<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;验证码错误</div>";
         result=false;
    }else {
        YzmCheck();
    }
}
function YzmCheck() {
    var codes=Trim(document.getElementById("Yzm").value);
    var url="ajax/check_code.php?code="+escape(codes);
    xmlHttp.open('get',url,true);
    xmlHttp.onreadystatechange=UpdateYzm;
    xmlHttp.send(null);
}

function UpdateYzm() {
    if (xmlHttp.readyState==3) {
        document.getElementById("regcode").innerHTML="<div class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;连接中</div>";
    }
    if (xmlHttp.readyState==4) {
        var cback=xmlHttp.responseText;
        if (cback=='1') {
             document.getElementById("regcode").innerHTML="<div class='Box_green'>&nbsp;&nbsp;&nbsp;&nbsp;</div>";
             result=true;
        }else if(cback=='0') {
             document.getElementById("regcode").innerHTML= "<div   class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;验证码错误</div>";
             result=false;
        }else{
             document.getElementById("regcode").innerHTML= "<div   class='Box_red'>&nbsp;&nbsp;&nbsp;&nbsp;服务器出错</div>";
             result=false;
        }
    }
}
function CheckForm() {
    if (document.getElementById("username").value=="") {
        document.getElementById("username").focus();
        alert("请输入用户名");
        return false;
    }
    var obj=Trim(document.getElementById("username").value);
    if (obj.length<6) {
        document.getElementById("username").focus();
        alert("用户名大于5位");
        return false;
    }
    if (document.getElementById("pwd").value=="") {
        document.getElementById("pwd").focus();
        alert("请输入密码");
        return false;
    }
    var pwd=Trim(document.getElementById("pwd").value);
    if (pwd.length<6) {
        document.getElementById("pwd").focus();
        alert("密码大于5位");
        return false;
    }
    if (document.getElementById("pwd1").value=="") {
        document.getElementById("pwd1").focus();
        alert("再次输入密码");
        return false;
    }
    var pwd1=Trim(document.getElementById("pwd1").value);
    if (pwd1!=pwd) {
        document.getElementById("pwd1").focus();
        alert("两次输入的密码不一致");
        return false;
    }
    if (document.getElementById("Email").value=="") {
        document.getElementById("Email").focus();
        alert("请输入邮箱");
        return false;
    }
    var email=Trim(document.getElementById("Email").value);
    if (!CheckEmailAddress(email)) {
        document.getElementById("Email").focus();
        alert("邮箱格式不正确");
        return false;
    }
    if (document.getElementById("Yzm").value=="") {
        document.getElementById("Yzm").focus();
        alert("请输入验证码");
        return false;
    }
    var codes=Trim(document.getElementById("Yzm").value);
    if (codes.length<4) {
        document.getElementById("Yzm").focus();
        alert("验证码输入错误");
        return false;
    }
    if (result==false) {
        document.getElementById("Yzm").focus();
        alert("验证码输入错误");
        return false;
    }
    return true;
}
function SubmitForm() {
        CheckRegName();
        CheckPwd();
        CheckRePwd();
        CheckEmail();
        CheckYzm();
        if (CheckForm()) {
           return true;
        }
	     return false;
}